﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Windows.Forms;
using Assist;
using Autodesk.Revit.DB;
using Autodesk.Revit.DB.Architecture;
using Autodesk.Revit.UI;
using YArchitech.Controls;
using YArchitech.LIB;
using YArchitech.LIB.YJKControls;
using YJKArchUtils.Utils;
using YJKRevitStairs.StairsModel.CommonUnit;
using YJKRevitStairs.StairsModel.DataInfos;
using YJKRevitStairs.StairsModel.Kit;

namespace YJKRevitStairs.StairsModel.Form
{
	public partial class CrossingStairsForm : EscBaseForm
	{
		public CrossingStairsForm(ExternalCommandData cmdData)
		{
			this.m_Revit = cmdData;
			this.m_StairsDrawingKit = new CrossingStairsKit(this.m_Revit.Application.Application);
			this.m_ComponentTypeManager = new ComponentTypeManager(this.m_Revit.Application.ActiveUIDocument.Document);
			this.m_listAllLevels = new List<Level>(YJKRevitStairs.StairsModel.CommonUnit.Common.GetSortLevels(this.m_Revit.Application.ActiveUIDocument.Document, double.MinValue, double.MaxValue));
			this.m_listStairsData = new List<double>();
			this.InitializeComponent();
			this.m_MainPreviewer = new Previewer(this, this.pnlPreview.Left, this.pnlPreview.Top, this.pnlPreview.Width, this.pnlPreview.Height, 1u);
			this.pnlPreview.Visible = false;
			base.MouseWheel += this.m_MainPreviewer.MouseWheel;
		}

		public double TopOffset
		{
			get
			{
				return YJKRevitStairs.StairsModel.CommonUnit.Common.StrToDouble(this.hyTbTopOffset.Text, 0.0);
			}
			set
			{
				this.hyTbTopOffset.Text = value.ToString("f2");
			}
		}

		public double BottomOffset
		{
			get
			{
				return YJKRevitStairs.StairsModel.CommonUnit.Common.StrToDouble(this.hyTbBottomOffset.Text, 0.0);
			}
			set
			{
				this.hyTbBottomOffset.Text = value.ToString("f2");
			}
		}

		public double RunWidth
		{
			get
			{
				return Convert.ToDouble(this.hyTbRunWidth.Text);
			}
			set
			{
				this.hyTbRunWidth.Text = value.ToString("f2");
			}
		}

		public double StairsWidth
		{
			get
			{
				return Convert.ToDouble(this.hyTbStairsWidth.Text);
			}
			set
			{
				this.hyTbStairsWidth.Text = value.ToString("f2");
			}
		}

		public double WellWidth
		{
			get
			{
				return Convert.ToDouble(this.hyTbWellWidth.Text);
			}
			set
			{
				this.hyTbWellWidth.Text = value.ToString("f2");
			}
		}

		public int TreadCount
		{
			get
			{
				return Convert.ToInt32(this.nudTreadCount.Value.ToString());
			}
			set
			{
				this.nudTreadCount.Value = value;
			}
		}

		public int OneRunTreadCount
		{
			get
			{
				return Convert.ToInt32(this.nudOneRunTreadCount.Value.ToString());
			}
			set
			{
				this.nudOneRunTreadCount.Value = value;
			}
		}

		public int TwoRunTreadCount
		{
			get
			{
				return Convert.ToInt32(this.nudTwoRunTreadCount.Value.ToString());
			}
			set
			{
				this.nudTwoRunTreadCount.Value = value;
			}
		}

		public double TreadHeight
		{
			get
			{
				return Convert.ToDouble(this.hyTbTreadHeight.Text);
			}
			set
			{
				this.hyTbTreadHeight.Text = value.ToString("f2");
			}
		}

		public double TreadDepth
		{
			get
			{
				return Convert.ToDouble(this.hyTbTreadDepth.Text);
			}
			set
			{
				this.hyTbTreadDepth.Text = value.ToString("f2");
			}
		}

		public string UsingRange
		{
			get
			{
				return this.comboUsingRange.Text;
			}
		}

		public int RunStructualDepth
		{
			get
			{
				return YJKRevitStairs.StairsModel.CommonUnit.Common.StrToInt(this.tbRunThickness.Text, 0);
			}
			set
			{
				this.tbRunThickness.Text = value.ToString();
			}
		}

		public int RunRiserThickness
		{
			get
			{
				return YJKRevitStairs.StairsModel.CommonUnit.Common.StrToInt(this.tbRiserThickness.Text, 0);
			}
			set
			{
				this.tbRiserThickness.Text = value.ToString();
			}
		}

		public int TreadThickness
		{
			get
			{
				return YJKRevitStairs.StairsModel.CommonUnit.Common.StrToInt(this.tbTreadThickness.Text, 0);
			}
			set
			{
				this.tbTreadThickness.Text = value.ToString();
			}
		}

		public double BeamWidth
		{
			get
			{
				return Convert.ToDouble(this.hyTbBeamWidth.Text);
			}
			set
			{
				this.hyTbBeamWidth.Text = value.ToString("f2");
			}
		}

		public double BeamHeight
		{
			get
			{
				return Convert.ToDouble(this.hyTbBeamHeight.Text);
			}
			set
			{
				this.hyTbBeamHeight.Text = value.ToString("f2");
			}
		}

		public double LandingWidth
		{
			get
			{
				return Convert.ToDouble(this.hyTbLandingWidth.Text);
			}
			set
			{
				this.hyTbLandingWidth.Text = value.ToString("f2");
			}
		}

		public int LandingThickness
		{
			get
			{
				return YJKRevitStairs.StairsModel.CommonUnit.Common.StrToInt(this.tbLandThickness.Text, 0);
			}
			set
			{
				this.tbLandThickness.Text = value.ToString();
			}
		}

		public double RotateAngle
		{
			get
			{
				return YJKRevitStairs.StairsModel.CommonUnit.Common.StrToDouble(this.hyTbRotateAngle.Text, 0.0) / 180.0 * Math.PI;
			}
			set
			{
				this.hyTbRotateAngle.Text = (value * 180.0 / Math.PI).ToString("f0");
			}
		}

		public XYZ BasePoint
		{
			get
			{
				return this.m_BasePoint;
			}
		}

		public CrossingStairsForm.MeasureType theMeasureType
		{
			get
			{
				return this.m_MeasureType;
			}
		}

		public LineRunData GetLeftUpRunData()
		{
			LineRunData lineRunData = new LineRunData();
			lineRunData.TheStairsType = this.m_ComponentTypeManager.GetStairsType();
			lineRunData.RunWidth = YJKRevitStairs.StairsModel.CommonUnit.Common.MMToFeet(this.RunWidth);
			lineRunData.TreadHeight = YJKRevitStairs.StairsModel.CommonUnit.Common.MMToFeet(this.TreadHeight);
			lineRunData.TreadDepth = YJKRevitStairs.StairsModel.CommonUnit.Common.MMToFeet(this.TreadDepth);
			if (this.rbLeftSideUp.Checked)
			{
				lineRunData.TreadCount = this.TwoRunTreadCount;
			}
			else
			{
				lineRunData.TreadCount = this.OneRunTreadCount;
			}
			lineRunData.RunLength = lineRunData.TreadDepth * (double)lineRunData.TreadCount;
			lineRunData.RunHeight = lineRunData.TreadHeight * (double)(lineRunData.TreadCount + 1);
			lineRunData.BottomElevation = YJKRevitStairs.StairsModel.CommonUnit.Common.MMToFeet(this.m_dBottomElevation);
			lineRunData.TreadThickness = YJKRevitStairs.StairsModel.CommonUnit.Common.MMToFeet((double)this.TreadThickness);
			lineRunData.RunStructualDepth = YJKRevitStairs.StairsModel.CommonUnit.Common.MMToFeet((double)this.RunStructualDepth);
			lineRunData.RiserThickness = YJKRevitStairs.StairsModel.CommonUnit.Common.MMToFeet((double)this.RunRiserThickness);
			return lineRunData;
		}

		public LineRunData GetLeftDownRunData()
		{
			LineRunData lineRunData = new LineRunData();
			lineRunData.TheStairsType = this.m_ComponentTypeManager.GetStairsType();
			lineRunData.RunWidth = YJKRevitStairs.StairsModel.CommonUnit.Common.MMToFeet(this.RunWidth);
			lineRunData.TreadHeight = YJKRevitStairs.StairsModel.CommonUnit.Common.MMToFeet(this.TreadHeight);
			lineRunData.TreadDepth = YJKRevitStairs.StairsModel.CommonUnit.Common.MMToFeet(this.TreadDepth);
			if (this.rbLeftSideUp.Checked)
			{
				lineRunData.TreadCount = this.OneRunTreadCount;
			}
			else
			{
				lineRunData.TreadCount = this.TwoRunTreadCount;
			}
			lineRunData.RunLength = lineRunData.TreadDepth * (double)lineRunData.TreadCount;
			lineRunData.RunHeight = lineRunData.TreadHeight * (double)(lineRunData.TreadCount + 1);
			lineRunData.BottomElevation = YJKRevitStairs.StairsModel.CommonUnit.Common.MMToFeet(this.m_dBottomElevation);
			lineRunData.TreadThickness = YJKRevitStairs.StairsModel.CommonUnit.Common.MMToFeet((double)this.TreadThickness);
			lineRunData.RunStructualDepth = YJKRevitStairs.StairsModel.CommonUnit.Common.MMToFeet((double)this.RunStructualDepth);
			lineRunData.RiserThickness = YJKRevitStairs.StairsModel.CommonUnit.Common.MMToFeet((double)this.RunRiserThickness);
			return lineRunData;
		}

		public LineRunData GetRightUpRunData()
		{
			LineRunData lineRunData = new LineRunData();
			lineRunData.TheStairsType = this.m_ComponentTypeManager.GetStairsType();
			lineRunData.RunWidth = YJKRevitStairs.StairsModel.CommonUnit.Common.MMToFeet(this.RunWidth);
			lineRunData.TreadHeight = YJKRevitStairs.StairsModel.CommonUnit.Common.MMToFeet(this.TreadHeight);
			lineRunData.TreadDepth = YJKRevitStairs.StairsModel.CommonUnit.Common.MMToFeet(this.TreadDepth);
			if (this.rbLeftSideUp.Checked)
			{
				lineRunData.TreadCount = this.OneRunTreadCount;
			}
			else
			{
				lineRunData.TreadCount = this.TwoRunTreadCount;
			}
			lineRunData.RunLength = lineRunData.TreadDepth * (double)lineRunData.TreadCount;
			lineRunData.RunHeight = lineRunData.TreadHeight * (double)(lineRunData.TreadCount + 1);
			lineRunData.BottomElevation = YJKRevitStairs.StairsModel.CommonUnit.Common.MMToFeet(this.m_dBottomElevation);
			lineRunData.TreadThickness = YJKRevitStairs.StairsModel.CommonUnit.Common.MMToFeet((double)this.TreadThickness);
			lineRunData.RunStructualDepth = YJKRevitStairs.StairsModel.CommonUnit.Common.MMToFeet((double)this.RunStructualDepth);
			lineRunData.RiserThickness = YJKRevitStairs.StairsModel.CommonUnit.Common.MMToFeet((double)this.RunRiserThickness);
			return lineRunData;
		}

		public LineRunData GetRightDownRunData()
		{
			LineRunData lineRunData = new LineRunData();
			lineRunData.TheStairsType = this.m_ComponentTypeManager.GetStairsType();
			lineRunData.RunWidth = YJKRevitStairs.StairsModel.CommonUnit.Common.MMToFeet(this.RunWidth);
			lineRunData.TreadHeight = YJKRevitStairs.StairsModel.CommonUnit.Common.MMToFeet(this.TreadHeight);
			lineRunData.TreadDepth = YJKRevitStairs.StairsModel.CommonUnit.Common.MMToFeet(this.TreadDepth);
			if (this.rbLeftSideUp.Checked)
			{
				lineRunData.TreadCount = this.TwoRunTreadCount;
			}
			else
			{
				lineRunData.TreadCount = this.OneRunTreadCount;
			}
			lineRunData.RunLength = lineRunData.TreadDepth * (double)lineRunData.TreadCount;
			lineRunData.RunHeight = lineRunData.TreadHeight * (double)(lineRunData.TreadCount + 1);
			lineRunData.BottomElevation = YJKRevitStairs.StairsModel.CommonUnit.Common.MMToFeet(this.m_dBottomElevation);
			lineRunData.TreadThickness = YJKRevitStairs.StairsModel.CommonUnit.Common.MMToFeet((double)this.TreadThickness);
			lineRunData.RunStructualDepth = YJKRevitStairs.StairsModel.CommonUnit.Common.MMToFeet((double)this.RunStructualDepth);
			lineRunData.RiserThickness = YJKRevitStairs.StairsModel.CommonUnit.Common.MMToFeet((double)this.RunRiserThickness);
			return lineRunData;
		}

		public List<BaseSupportData> GetSupportData()
		{
			List<BaseSupportData> list = new List<BaseSupportData>();
			if (this.chkOutSupport.Checked)
			{
				list.Add(new BaseSupportData
				{
					SupportType = this.m_ComponentTypeManager.GetSupportType(this.cmbSupport.SelectedIndex),
					Style = SupportStyle.ST_OutSide
				});
			}
			if (this.chkMiddleSupport.Checked)
			{
				list.Add(new BaseSupportData
				{
					SupportType = this.m_ComponentTypeManager.GetSupportType(this.cmbSupport.SelectedIndex),
					Style = SupportStyle.ST_Mid,
					nSurportNum = 3
				});
			}
			if (this.chkInsideSupport.Checked)
			{
				list.Add(new BaseSupportData
				{
					SupportType = this.m_ComponentTypeManager.GetSupportType(this.cmbSupport.SelectedIndex),
					Style = SupportStyle.ST_Inside
				});
			}
			return list;
		}

		public BaseLandingData GetLandingData()
		{
			return new BaseLandingData
			{
				TheType = LandingType.LT_Crossing,
				Width = YJKRevitStairs.StairsModel.CommonUnit.Common.MMToFeet(this.LandingWidth),
				BottomElevation = YJKRevitStairs.StairsModel.CommonUnit.Common.MMToFeet(this.m_dBottomElevation) + (double)(this.OneRunTreadCount + 1) * YJKRevitStairs.StairsModel.CommonUnit.Common.MMToFeet(this.TreadHeight),
				LandingThickness = YJKRevitStairs.StairsModel.CommonUnit.Common.MMToFeet((double)this.LandingThickness)
			};
		}

		public BaseBeamData GetBeamData()
		{
			return new BaseBeamData
			{
				BeamHeight = YJKRevitStairs.StairsModel.CommonUnit.Common.MMToFeet(this.BeamHeight),
				BeamWidth = YJKRevitStairs.StairsModel.CommonUnit.Common.MMToFeet(this.BeamWidth)
			};
		}

        public YJKRevitStairs.StairsModel.DataInfos.FloorType GetFloorType()
		{
			if (this.rbFirstFloor.Checked)
			{
                return YJKRevitStairs.StairsModel.DataInfos.FloorType.FT_Bottom;
			}
			if (this.rbMiddleFloor.Checked)
			{
                return YJKRevitStairs.StairsModel.DataInfos.FloorType.FT_Mid;
			}
            return YJKRevitStairs.StairsModel.DataInfos.FloorType.FT_Top;
		}

		public List<string> GetLandWidth()
		{
			return new List<string>
			{
				this.LandingWidth.ToString("f2")
			};
		}

		public int GetTreadAlignType()
		{
			int result;
			if (this.rbPlatformAlign.Checked)
			{
				result = 0;
			}
			else if (this.rbCenterAlign.Checked)
			{
				result = 1;
			}
			else
			{
				result = 2;
			}
			return result;
		}

		public bool GetUpstairs()
		{
			return this.m_bLeftSideUp;
		}

		public bool GetNoteInfo()
		{
			return this.chkNoteInfo.Checked;
		}

		public bool GetTBMirror()
		{
			return this.chkTBMirror.Checked;
		}

		public bool GetLRMirror()
		{
			return this.chkLRMirror.Checked;
		}

		public int GetInsertPointIndex()
		{
			return this.m_BasePointIndex;
		}

		public bool GetMiddleBeam()
		{
			return this.chkMiddleBeam.Checked;
		}

		public double GetBottomElevation()
		{
			return this.m_BottomLevel.Elevation;
		}

		public double GetLevelValue()
		{
			return YJKRevitStairs.StairsModel.CommonUnit.Common.MMToFeet(this.m_dLevelValue);
		}

		public double GetTopOffset()
		{
			return this.TopOffset;
		}

		public bool GetInnerRail()
		{
			return this.chkInnerRailing.Checked;
		}

		public RailingType GetInnerRailType()
		{
			return this.m_ComponentTypeManager.GetRailingType(this.cmbInnerRailingType.SelectedIndex);
		}

		public double GetInnerRailHeight()
		{
			return YJKRevitStairs.StairsModel.CommonUnit.Common.MMToFeet(Convert.ToDouble(this.m_ComponentTypeManager.GetHeightsOfRailingTypeList()[this.cmbInnerRailingType.SelectedIndex]));
		}

		public bool GetOuterRail()
		{
			return this.chkOutRailing.Checked;
		}

		public RailingType GetOuterRailType()
		{
			return this.m_ComponentTypeManager.GetRailingType(this.cmbOutRailingType.SelectedIndex);
		}

		public double GetOuterRailHeight()
		{
			return YJKRevitStairs.StairsModel.CommonUnit.Common.MMToFeet(Convert.ToDouble(this.m_ComponentTypeManager.GetHeightsOfRailingTypeList()[this.cmbOutRailingType.SelectedIndex]));
		}

		protected override void DefWndProc(ref Message m)
		{
			int msg = m.Msg;
			if (msg == 1125)
			{
				if (m.WParam.ToInt32() != 1)
				{
					return;
				}
				List<CurveInfo> curves = new List<CurveInfo>();
				List<TextNoteInfo> textNotes = new List<TextNoteInfo>();
				try
				{
					this.GetProfileCurves(ref curves, ref textNotes);
					this.m_MainPreviewer.Curves = curves;
					this.m_MainPreviewer.TextNotes = textNotes;
					return;
				}
				catch (Exception)
				{
					return;
				}
			}
			base.DefWndProc(ref m);
		}

		private void GetProfileCurves(ref List<CurveInfo> curvesInfoList, ref List<TextNoteInfo> textNoteInfoList)
		{
			CrossingStairs crossingStairs = new CrossingStairs();
			crossingStairs.m_LeftUpRunData = this.GetLeftUpRunData();
			crossingStairs.m_LeftDownRunData = this.GetLeftDownRunData();
			crossingStairs.m_RightUpRunData = this.GetRightUpRunData();
			crossingStairs.m_RightDownRunData = this.GetRightDownRunData();
			crossingStairs.m_LandData = this.GetLandingData();
			crossingStairs.m_BeamData = this.GetBeamData();
			crossingStairs.m_FloorType = this.GetFloorType();
			crossingStairs.m_dStairsWidth = YJKRevitStairs.StairsModel.CommonUnit.Common.MMToFeet(this.StairsWidth);
			int treadAlignType = this.GetTreadAlignType();
			this.m_StairsDrawingKit.CrossingStairsProfileCurves(ref crossingStairs, this.chkNoteInfo.Checked, treadAlignType, this.m_BasePointIndex, this.chkLRMirror.Checked, this.chkTBMirror.Checked, this.m_bLeftSideUp, this.RotateAngle, this.chkMiddleBeam.Checked);
			foreach (SingleRunCurveInfo singleRunCurveInfo in crossingStairs.m_listRunCurve)
			{
				curvesInfoList.AddRange(singleRunCurveInfo.RunBoundaryCurvesInfoList);
				curvesInfoList.AddRange(singleRunCurveInfo.RunRiserCurvesInfoList);
				curvesInfoList.AddRange(singleRunCurveInfo.RunPathCurvesInfoList);
			}
			foreach (LandingCurveInfo landingCurveInfo in crossingStairs.m_listLandCurve)
			{
				curvesInfoList.AddRange(landingCurveInfo.m_arCurveInfo);
			}
			curvesInfoList.AddRange(crossingStairs.m_listOtherCurve);
			textNoteInfoList = crossingStairs.m_listText;
		}

		private void ReadData()
		{
			string path = Product.UserDataLocation + "CrossingStairsForm.dat";
			if (!File.Exists(path))
			{
				this.m_Calculating = true;
				this.comboUsingRange.Text = "住宅共用楼梯（有电梯）";
				this.hyTbTopOffset.Text = "0.00";
				this.hyTbBottomOffset.Text = "0.00";
				this.hyTbStairsWidth.Text = "2600.00";
				this.hyTbRunWidth.Text = "1200.00";
				this.hyTbWellWidth.Text = "200.00";
				this.nudTreadCount.Value = 24m;
				this.nudOneRunTreadCount.Value = 12m;
				this.nudTwoRunTreadCount.Value = 12m;
				this.hyTbTreadHeight.Text = "170.00";
				this.hyTbTreadDepth.Text = "260.00";
				this.tbRunThickness.Text = "120";
				this.tbLandThickness.Text = "120";
				this.tbRiserThickness.Text = "30";
				this.tbTreadThickness.Text = "30";
				this.chkInnerRailing.Checked = true;
				this.chkOutRailing.Checked = true;
				this.chkOutSupport.Checked = false;
				this.chkMiddleSupport.Checked = false;
				this.chkInsideSupport.Checked = false;
				this.chkMiddleBeam.Checked = true;
				this.hyTbBeamWidth.Text = "200.00";
				this.hyTbBeamHeight.Text = "400.00";
				this.rbFirstFloor.Checked = false;
				this.rbMiddleFloor.Checked = true;
				this.rbTopFloor.Checked = false;
				this.rbPlatformAlign.Checked = false;
				this.rbCenterAlign.Checked = true;
				this.rbFloorslabAlign.Checked = false;
				this.rbLeftSideUp.Checked = true;
				this.rbRightSideUp.Checked = false;
				this.hyTbLandingWidth.Text = "1200.00";
				this.hyTbRotateAngle.Text = "0.00";
				this.chkTBMirror.Checked = false;
				this.chkLRMirror.Checked = false;
				this.chkNoteInfo.Checked = true;
				this.m_Calculating = false;
				return;
			}
			this.m_Calculating = true;
			FileStream fileStream = new FileStream(path, FileMode.Open);
			StreamReader streamReader = new StreamReader(fileStream);
			streamReader.BaseStream.Seek(0L, SeekOrigin.Begin);
			int index = Convert.ToInt32(streamReader.ReadLine());
			this.SetComboBoxSelectedIndex(this.comboUsingRange, index);
			this.hyTbTopOffset.Text = YJKRevitStairs.StairsModel.CommonUnit.Common.StrToDouble(streamReader.ReadLine(), 0.0).ToString("f2");
			this.hyTbBottomOffset.Text = YJKRevitStairs.StairsModel.CommonUnit.Common.StrToDouble(streamReader.ReadLine(), 0.0).ToString("f2");
			this.hyTbStairsWidth.Text = Convert.ToDouble(streamReader.ReadLine()).ToString("f2");
			this.hyTbRunWidth.Text = Convert.ToDouble(streamReader.ReadLine()).ToString("f2");
			this.hyTbWellWidth.Text = Convert.ToDouble(streamReader.ReadLine()).ToString("f2");
			this.nudTreadCount.Value = Convert.ToInt32(streamReader.ReadLine());
			this.nudOneRunTreadCount.Value = Convert.ToInt32(streamReader.ReadLine());
			this.nudTwoRunTreadCount.Value = Convert.ToInt32(streamReader.ReadLine());
			this.hyTbTreadHeight.Text = Convert.ToDouble(streamReader.ReadLine()).ToString("f2");
			this.hyTbTreadDepth.Text = Convert.ToDouble(streamReader.ReadLine()).ToString("f2");
			this.tbRunThickness.Text = YJKRevitStairs.StairsModel.CommonUnit.Common.StrToInt(streamReader.ReadLine(), 120).ToString();
			this.tbLandThickness.Text = YJKRevitStairs.StairsModel.CommonUnit.Common.StrToInt(streamReader.ReadLine(), 120).ToString();
			this.tbRiserThickness.Text = YJKRevitStairs.StairsModel.CommonUnit.Common.StrToInt(streamReader.ReadLine(), 30).ToString();
			this.tbTreadThickness.Text = YJKRevitStairs.StairsModel.CommonUnit.Common.StrToInt(streamReader.ReadLine(), 30).ToString();
			this.chkInnerRailing.Checked = Convert.ToBoolean(streamReader.ReadLine());
			this.chkOutRailing.Checked = Convert.ToBoolean(streamReader.ReadLine());
			index = Convert.ToInt32(streamReader.ReadLine());
			this.SetComboBoxSelectedIndex(this.cmbInnerRailingType, index);
			index = Convert.ToInt32(streamReader.ReadLine());
			this.SetComboBoxSelectedIndex(this.cmbOutRailingType, index);
			this.chkOutSupport.Checked = Convert.ToBoolean(streamReader.ReadLine());
			this.chkMiddleSupport.Checked = Convert.ToBoolean(streamReader.ReadLine());
			this.chkInsideSupport.Checked = Convert.ToBoolean(streamReader.ReadLine());
			index = Convert.ToInt32(streamReader.ReadLine());
			this.SetComboBoxSelectedIndex(this.cmbSupport, index);
			this.chkMiddleBeam.Checked = Convert.ToBoolean(streamReader.ReadLine());
			this.hyTbBeamWidth.Text = Convert.ToDouble(streamReader.ReadLine()).ToString("f2");
			this.hyTbBeamHeight.Text = Convert.ToDouble(streamReader.ReadLine()).ToString("f2");
			int num = Convert.ToInt32(streamReader.ReadLine());
			if (num == 0)
			{
				this.rbFirstFloor.Checked = true;
				this.rbMiddleFloor.Checked = false;
				this.rbTopFloor.Checked = false;
			}
			else if (1 == num)
			{
				this.rbFirstFloor.Checked = false;
				this.rbMiddleFloor.Checked = true;
				this.rbTopFloor.Checked = false;
			}
			else
			{
				this.rbFirstFloor.Checked = false;
				this.rbMiddleFloor.Checked = false;
				this.rbTopFloor.Checked = true;
			}
			int num2 = Convert.ToInt32(streamReader.ReadLine());
			if (num2 == 0)
			{
				this.rbPlatformAlign.Checked = true;
				this.rbCenterAlign.Checked = false;
				this.rbFloorslabAlign.Checked = false;
			}
			else if (1 == num2)
			{
				this.rbPlatformAlign.Checked = false;
				this.rbCenterAlign.Checked = true;
				this.rbFloorslabAlign.Checked = false;
			}
			else
			{
				this.rbPlatformAlign.Checked = false;
				this.rbCenterAlign.Checked = false;
				this.rbFloorslabAlign.Checked = true;
			}
			if (Convert.ToInt32(streamReader.ReadLine()) == 0)
			{
				this.rbLeftSideUp.Checked = true;
				this.rbRightSideUp.Checked = false;
			}
			else
			{
				this.rbLeftSideUp.Checked = false;
				this.rbRightSideUp.Checked = true;
			}
			this.hyTbLandingWidth.Text = Convert.ToDouble(streamReader.ReadLine()).ToString("f2");
			this.hyTbRotateAngle.Text = YJKRevitStairs.StairsModel.CommonUnit.Common.StrToDouble(streamReader.ReadLine(), 0.0).ToString("f2");
			this.m_BasePointIndex = Convert.ToInt32(streamReader.ReadLine());
			this.chkTBMirror.Checked = Convert.ToBoolean(streamReader.ReadLine());
			this.chkLRMirror.Checked = Convert.ToBoolean(streamReader.ReadLine());
			this.chkNoteInfo.Checked = Convert.ToBoolean(streamReader.ReadLine());
			streamReader.Close();
			fileStream.Close();
			this.m_Calculating = false;
		}

		public void SaveData()
		{
			FileStream fileStream = new FileStream(Product.UserDataLocation + "CrossingStairsForm.dat", FileMode.Create);
			StreamWriter streamWriter = new StreamWriter(fileStream);
			streamWriter.WriteLine(this.comboUsingRange.SelectedIndex);
			streamWriter.WriteLine(this.hyTbTopOffset.Text);
			streamWriter.WriteLine(this.hyTbBottomOffset.Text);
			streamWriter.WriteLine(this.hyTbStairsWidth.Text);
			streamWriter.WriteLine(this.hyTbRunWidth.Text);
			streamWriter.WriteLine(this.hyTbWellWidth.Text);
			streamWriter.WriteLine(this.nudTreadCount.Value.ToString());
			streamWriter.WriteLine(this.nudOneRunTreadCount.Value.ToString());
			streamWriter.WriteLine(this.nudTwoRunTreadCount.Value.ToString());
			streamWriter.WriteLine(this.hyTbTreadHeight.Text);
			streamWriter.WriteLine(this.hyTbTreadDepth.Text);
			streamWriter.WriteLine(this.tbRunThickness.Text);
			streamWriter.WriteLine(this.tbLandThickness.Text);
			streamWriter.WriteLine(this.tbRiserThickness.Text);
			streamWriter.WriteLine(this.tbTreadThickness.Text);
			streamWriter.WriteLine(this.chkInnerRailing.Checked);
			streamWriter.WriteLine(this.chkOutRailing.Checked);
			streamWriter.WriteLine(this.cmbInnerRailingType.SelectedIndex);
			streamWriter.WriteLine(this.cmbOutRailingType.SelectedIndex);
			streamWriter.WriteLine(this.chkOutSupport.Checked);
			streamWriter.WriteLine(this.chkMiddleSupport.Checked);
			streamWriter.WriteLine(this.chkInsideSupport.Checked);
			streamWriter.WriteLine(this.cmbSupport.SelectedIndex);
			streamWriter.WriteLine(this.chkMiddleBeam.Checked);
			streamWriter.WriteLine(this.hyTbBeamWidth.Text);
			streamWriter.WriteLine(this.hyTbBeamHeight.Text);
			if (this.rbFirstFloor.Checked)
			{
				streamWriter.WriteLine(0);
			}
			else if (this.rbMiddleFloor.Checked)
			{
				streamWriter.WriteLine(1);
			}
			else
			{
				streamWriter.WriteLine(2);
			}
			if (this.rbPlatformAlign.Checked)
			{
				streamWriter.WriteLine(0);
			}
			else if (this.rbCenterAlign.Checked)
			{
				streamWriter.WriteLine(1);
			}
			else
			{
				streamWriter.WriteLine(2);
			}
			if (this.rbLeftSideUp.Checked)
			{
				streamWriter.WriteLine(0);
			}
			else
			{
				streamWriter.WriteLine(1);
			}
			streamWriter.WriteLine(this.hyTbLandingWidth.Text);
			streamWriter.WriteLine(this.hyTbRotateAngle.Text);
			streamWriter.WriteLine(this.m_BasePointIndex);
			streamWriter.WriteLine(this.chkTBMirror.Checked);
			streamWriter.WriteLine(this.chkLRMirror.Checked);
			streamWriter.WriteLine(this.chkNoteInfo.Checked);
			streamWriter.Flush();
			streamWriter.Close();
			fileStream.Close();
		}

		private void CrossingStairsForm_Load(object sender, EventArgs e)
		{
			//base.Icon = Resource.YArchitechIcon;
			this.InitializeComboBox(this.comboUsingRange, this.m_ComponentTypeManager.GetUsingRangeList());
			this.InitializeComboBox(this.cmbInnerRailingType, this.m_ComponentTypeManager.GetRailingTypeNameList());
			this.InitializeComboBox(this.cmbOutRailingType, this.m_ComponentTypeManager.GetRailingTypeNameList());
			this.InitializeComboBox(this.cmbSupport, this.m_ComponentTypeManager.GetSupportTypeNameList());
			List<string> list = new List<string>();
			foreach (Element element in this.m_listAllLevels)
			{
				if (!list.Contains(element.Name))
				{
					list.Add(element.Name);
				}
			}
			this.InitializeComboBox(this.cmbTopLevel, list);
			this.InitializeComboBox(this.cmbBottomLevel, list);
			this.ReadData();
			this.UpdateRailingData();
			this.UpdateSupportData();
			this.UpdateBeamData();
			this.UpdateStairsData();
			this.m_BottomLevel = this.m_Revit.Application.ActiveUIDocument.ActiveView.GenLevel;
			for (int i = 0; i < this.m_listAllLevels.Count; i++)
			{
				if (this.m_BottomLevel.Id == this.m_listAllLevels.ElementAt(i).Id)
				{
					if (this.m_listAllLevels.Count - 1 == i)
					{
						this.m_TopLevel = this.m_BottomLevel;
						this.cmbTopLevel.SelectedIndex = i;
						this.m_dLevelValue = YJKRevitStairs.StairsModel.CommonUnit.Common.FeetToMM(this.m_BottomLevel.Elevation - this.m_listAllLevels.ElementAt(i - 1).Elevation);
						this.TopOffset = this.m_dLevelValue;
					}
					else
					{
						this.m_TopLevel = this.m_listAllLevels.ElementAt(i + 1);
						this.cmbTopLevel.SelectedIndex = i + 1;
						this.m_dLevelValue = YJKRevitStairs.StairsModel.CommonUnit.Common.FeetToMM(this.m_TopLevel.Elevation - this.m_BottomLevel.Elevation);
						this.TopOffset = 0.0;
					}
					this.cmbBottomLevel.SelectedIndex = i;
					break;
				}
			}
			this.BottomOffset = 0.0;
		}

		private void CrossingStairsForm_FormClosing(object sender, FormClosingEventArgs e)
		{
			if (DialogResult.Cancel == base.DialogResult)
			{
				return;
			}
			string text = "";
			if (!this.ValidatingParameters(ref text))
			{
				MessageBox.Show(text, "盈建科提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
				e.Cancel = true;
			}
			this.SaveData();
		}

		private void InitializeComboBox(System.Windows.Forms.ComboBox control, List<string> typeNameList)
		{
			control.Items.Clear();
			foreach (string item in typeNameList)
			{
				control.Items.Add(item);
			}
			if (control.Items.Count > 0)
			{
				control.SelectedIndex = 0;
			}
		}

		private void SetComboBoxSelectedIndex(System.Windows.Forms.ComboBox control, int index)
		{
			if (index < 0 || index >= control.Items.Count)
			{
				return;
			}
			control.SelectedIndex = index;
		}

		private bool ValidatingParameters(ref string message)
		{
			if (this.chkInnerRailing.Checked || this.chkOutRailing.Checked)
			{
				if (this.cmbInnerRailingType.Items.Count == 0)
				{
					message = "栏杆类型为空";
					return false;
				}
				if (this.cmbOutRailingType.Items.Count == 0)
				{
					message = "栏杆类型为空";
					return false;
				}
			}
			if ((this.chkOutSupport.Checked || this.chkMiddleSupport.Checked || this.chkInsideSupport.Checked) && this.cmbSupport.Items.Count == 0)
			{
				message = "支持类型为空";
				return false;
			}
			return true;
		}

		private bool ValidatingDataParam(ref string message)
		{
			List<ValidatingData> list = new List<ValidatingData>();
			ValidatingData item = new ValidatingData
			{
				Type = DataType.DT_RunWidth,
				Name = "梯段宽度",
				Value = this.RunWidth
			};
			list.Add(item);
			item.Type = DataType.DT_TreadHeight;
			item.Name = "踏步高度";
			item.Value = this.TreadHeight;
			list.Add(item);
			item.Type = DataType.DT_TreadDepth;
			item.Name = "踏步宽度";
			item.Value = this.TreadDepth;
			list.Add(item);
			item.Type = DataType.DT_TreadCount;
			item.Name = "一跑步数";
			item.Count = this.OneRunTreadCount;
			list.Add(item);
			item.Type = DataType.DT_TreadCount;
			item.Name = "二跑步数";
			item.Count = this.TwoRunTreadCount;
			list.Add(item);
			item.Type = DataType.DT_LandWidth;
			item.Name = "平台宽度";
			item.Value = this.LandingWidth;
			list.Add(item);
			message = FormParamManager.GetValidatingData(list, this.UsingRange, 0.0);
			return message == null;
		}

		private void ParametersCalculate(CrossingStairsForm.ParametersChangeType changeType)
		{
			if (this.m_Calculating)
			{
				return;
			}
			this.m_Calculating = true;
			try
			{
				double stairsHeight = FormParamManager.GetStairsHeight(this.m_dLevelValue, this.TopOffset, this.BottomOffset);
				int num = FormParamManager.GetStairsTreadCount(stairsHeight, this.TreadHeight) - 2;
				switch (changeType)
				{
				case CrossingStairsForm.ParametersChangeType.PCT_TreadHeight:
					if (num % 2 == 0)
					{
						this.OneRunTreadCount = num / 2;
						this.TwoRunTreadCount = this.OneRunTreadCount;
					}
					else
					{
						this.OneRunTreadCount = num / 2;
						this.TwoRunTreadCount = this.OneRunTreadCount + 1;
					}
					this.TreadCount = this.OneRunTreadCount + this.TwoRunTreadCount;
					break;
				case CrossingStairsForm.ParametersChangeType.PCT_TreadCountAdd:
					this.TreadCountChanged(true);
					this.TreadHeight = stairsHeight / (double)(this.TreadCount + 2);
					break;
				case CrossingStairsForm.ParametersChangeType.PCT_TreadCountSub:
					if (6 > this.TreadCount)
					{
						int num2 = this.TreadCount;
						this.TreadCount = num2 + 1;
					}
					else
					{
						this.TreadCountChanged(false);
					}
					this.TreadHeight = stairsHeight / (double)(this.TreadCount + 2);
					break;
				case CrossingStairsForm.ParametersChangeType.PCT_OneRunTreadCountAdd:
					if (3 < this.TwoRunTreadCount)
					{
						this.OneRunTreadCountChanged(true);
					}
					else
					{
						int num2 = this.OneRunTreadCount;
						this.OneRunTreadCount = num2 - 1;
					}
					break;
				case CrossingStairsForm.ParametersChangeType.PCT_OneRunTreadCountSub:
					if (3 > this.OneRunTreadCount)
					{
						int num2 = this.OneRunTreadCount;
						this.OneRunTreadCount = num2 + 1;
					}
					else
					{
						this.OneRunTreadCountChanged(false);
					}
					break;
				case CrossingStairsForm.ParametersChangeType.PCT_TwoRunTreadCountAdd:
					if (3 < this.OneRunTreadCount)
					{
						this.TwoRunTreadCountChanged(true);
					}
					else
					{
						int num2 = this.TwoRunTreadCount;
						this.TwoRunTreadCount = num2 - 1;
					}
					break;
				case CrossingStairsForm.ParametersChangeType.PCT_TwoRunTreadCountSub:
					if (3 > this.TwoRunTreadCount)
					{
						int num2 = this.TwoRunTreadCount;
						this.TwoRunTreadCount = num2 + 1;
					}
					else
					{
						this.TwoRunTreadCountChanged(false);
					}
					break;
				}
				this.m_Calculating = false;
			}
			catch (Exception)
			{
				this.m_Calculating = false;
			}
		}

		private void CalcCmpTreadCount()
		{
			try
			{
				int num = FormParamManager.GetStairsTreadCount(FormParamManager.GetStairsHeight(this.m_dLevelValue, this.TopOffset, this.BottomOffset), this.TreadHeight) - 2;
				if (num % 2 == 0)
				{
					this.m_nOneRunCmpTreadCnt = num / 2;
					this.m_nTwoRunCmpTreadCnt = this.m_nOneRunCmpTreadCnt;
				}
				else
				{
					this.m_nOneRunCmpTreadCnt = num / 2;
					this.m_nTwoRunCmpTreadCnt = this.m_nOneRunCmpTreadCnt + 1;
				}
			}
			catch
			{
				this.m_nOneRunCmpTreadCnt = 2;
				this.m_nTwoRunCmpTreadCnt = 2;
			}
		}

		private bool IsNotValidRunMinTread()
		{
			bool result = false;
			this.CalcCmpTreadCount();
			if (this.m_nOneRunCmpTreadCnt < FormParamManager.m_nRunMinTreadCount || this.m_nTwoRunCmpTreadCnt < FormParamManager.m_nRunMinTreadCount)
			{
				result = true;
			}
			return result;
		}

		private CrossingStairsForm.ValveChangeType isAddNumericUpDown(NumericUpDown ctrl)
		{
			int num = Convert.ToInt32(ctrl.Text);
			int num2 = Convert.ToInt32(ctrl.Value.ToString());
			if (num2 == num)
			{
				return CrossingStairsForm.ValveChangeType.VCT_None;
			}
			if (num2 == num + 1)
			{
				return CrossingStairsForm.ValveChangeType.VCT_AddOne;
			}
			if (num2 + 1 == num)
			{
				return CrossingStairsForm.ValveChangeType.VCT_SubtractOne;
			}
			return CrossingStairsForm.ValveChangeType.VCT_ValveChanged;
		}

		private void TreadCountChanged(bool isAdd)
		{
			if (this.TreadCount % 2 == 0)
			{
				this.OneRunTreadCount = this.TreadCount / 2;
				this.TwoRunTreadCount = this.OneRunTreadCount;
				return;
			}
			this.OneRunTreadCount = this.TreadCount / 2;
			this.TwoRunTreadCount = this.OneRunTreadCount + 1;
		}

		private void OneRunTreadCountChanged(bool isAdd)
		{
			if (isAdd)
			{
				this.nudTwoRunTreadCount.Value = this.nudTwoRunTreadCount.Value - 1m;
				return;
			}
			this.nudTwoRunTreadCount.Value = this.nudTwoRunTreadCount.Value + 1m;
		}

		private void TwoRunTreadCountChanged(bool isAdd)
		{
			if (isAdd)
			{
				this.nudOneRunTreadCount.Value = this.nudOneRunTreadCount.Value - 1m;
				return;
			}
			this.nudOneRunTreadCount.Value = this.nudOneRunTreadCount.Value + 1m;
		}

		private void UpdateRailingData()
		{
			if (!this.chkInnerRailing.Checked)
			{
				this.cmbInnerRailingType.Enabled = false;
			}
			else
			{
				this.cmbInnerRailingType.Enabled = true;
			}
			if (!this.chkOutRailing.Checked)
			{
				this.cmbOutRailingType.Enabled = false;
				return;
			}
			this.cmbOutRailingType.Enabled = true;
		}

		private void UpdateSupportData()
		{
			if (!this.chkOutSupport.Checked && !this.chkInsideSupport.Checked)
			{
				this.cmbSupport.Enabled = false;
				return;
			}
			this.cmbSupport.Enabled = true;
		}

		private void UpdateBeamData()
		{
			if (!this.chkMiddleBeam.Checked)
			{
				this.hyTbBeamWidth.Enabled = false;
				this.hyTbBeamHeight.Enabled = false;
				return;
			}
			this.hyTbBeamWidth.Enabled = true;
			this.hyTbBeamHeight.Enabled = true;
		}

		private void UpdateStairsData()
		{
			this.m_listStairsData.Clear();
			this.m_listStairsData.Add(this.RunWidth);
			this.m_listStairsData.Add(this.StairsWidth);
			this.m_listStairsData.Add(this.TreadHeight);
			this.m_listStairsData.Add(this.TreadDepth);
			this.m_listStairsData.Add(this.BeamWidth);
			this.m_listStairsData.Add(this.BeamHeight);
			this.m_listStairsData.Add(this.LandingWidth);
			this.m_listStairsData.Add(this.RotateAngle);
		}

		private void chkInnerRailing_CheckedChanged(object sender, EventArgs e)
		{
			this.UpdateRailingData();
			this.m_MainPreviewer.Refresh();
		}

		private void chkOutRailing_CheckedChanged(object sender, EventArgs e)
		{
			this.UpdateRailingData();
			this.m_MainPreviewer.Refresh();
		}

		private void chkOutSupport_CheckedChanged(object sender, EventArgs e)
		{
			this.UpdateSupportData();
			this.m_MainPreviewer.Refresh();
		}

		private void chkMiddleSupport_CheckedChanged(object sender, EventArgs e)
		{
			this.UpdateSupportData();
			this.m_MainPreviewer.Refresh();
		}

		private void chkInsideSupport_CheckedChanged(object sender, EventArgs e)
		{
			this.UpdateSupportData();
			this.m_MainPreviewer.Refresh();
		}

		private void chkMiddleBeam_CheckedChanged(object sender, EventArgs e)
		{
			this.UpdateBeamData();
			this.m_MainPreviewer.Refresh();
		}

		private void rbFirstFloor_CheckedChanged(object sender, EventArgs e)
		{
			this.m_MainPreviewer.Refresh();
		}

		private void rbMiddleFloor_CheckedChanged(object sender, EventArgs e)
		{
			this.m_MainPreviewer.Refresh();
		}

		private void rbTopFloor_CheckedChanged(object sender, EventArgs e)
		{
			this.m_MainPreviewer.Refresh();
		}

		private void rbPlatformAlign_CheckedChanged(object sender, EventArgs e)
		{
			this.m_MainPreviewer.Refresh();
		}

		private void rbCenterAlign_CheckedChanged(object sender, EventArgs e)
		{
			this.m_MainPreviewer.Refresh();
		}

		private void rbFloorslabAlign_CheckedChanged(object sender, EventArgs e)
		{
			this.m_MainPreviewer.Refresh();
		}

		private void rbLeftSideUp_CheckedChanged(object sender, EventArgs e)
		{
			this.m_bLeftSideUp = true;
			this.m_MainPreviewer.Refresh();
		}

		private void rbRightSideUp_CheckedChanged(object sender, EventArgs e)
		{
			this.m_bLeftSideUp = false;
			this.m_MainPreviewer.Refresh();
		}

		private void chkNoteInfo_CheckedChanged(object sender, EventArgs e)
		{
			this.m_MainPreviewer.Refresh();
		}

		private void chkLRMirror_CheckedChanged(object sender, EventArgs e)
		{
			this.m_MainPreviewer.Refresh();
		}

		private void chkTBMirror_CheckedChanged(object sender, EventArgs e)
		{
			this.m_MainPreviewer.Refresh();
		}

		private void hyTbTopOffset_TextChanged(object sender, EventArgs e)
		{
			this.ParametersCalculate(CrossingStairsForm.ParametersChangeType.PCT_TreadHeight);
			this.m_MainPreviewer.Refresh();
		}

		private void hyTbBottomOffset_TextChanged(object sender, EventArgs e)
		{
			this.ParametersCalculate(CrossingStairsForm.ParametersChangeType.PCT_TreadHeight);
			this.m_MainPreviewer.Refresh();
		}

		private void hyTbTreadHeight_TextChanged(object sender, EventArgs e)
		{
			this.ParametersCalculate(CrossingStairsForm.ParametersChangeType.PCT_TreadHeight);
			this.m_MainPreviewer.Refresh();
		}

		private void hyTbTreadDepth_TextChanged(object sender, EventArgs e)
		{
			this.m_MainPreviewer.Refresh();
		}

		private void hyTbBeamWidth_TextChanged(object sender, EventArgs e)
		{
			this.m_MainPreviewer.Refresh();
		}

		private void hyTbBeamHeight_TextChanged(object sender, EventArgs e)
		{
			this.m_MainPreviewer.Refresh();
		}

		private void hyTbLandingWidth_TextChanged(object sender, EventArgs e)
		{
			if (ValueValidatingKit.IsInvalidLandingWidthRange(YJKRevitStairs.StairsModel.CommonUnit.Common.StrToDouble(this.hyTbLandingWidth.Text, 0.0)))
			{
				this.hyTbLandingWidth.Text = (this.hyTbLandingWidth.Tag as string);
			}
			this.m_MainPreviewer.Refresh();
			this.hyTbLandingWidth.Tag = this.hyTbLandingWidth.Text;
		}

		private void hyTbRotateAngle_TextChanged(object sender, EventArgs e)
		{
			this.m_MainPreviewer.Refresh();
		}

		private void cmbTopLevel_TextChanged(object sender, EventArgs e)
		{
			if (this.cmbBottomLevel.SelectedIndex > this.cmbTopLevel.SelectedIndex && this.cmbTopLevel.SelectedIndex == 0)
			{
				return;
			}
			if (this.cmbBottomLevel.SelectedIndex > this.cmbTopLevel.SelectedIndex)
			{
				MessageBox.Show("楼梯顶高低于楼梯底部.", "盈建科提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
				return;
			}
		}

		private void cmbBottomLevel_TextChanged(object sender, EventArgs e)
		{
			if (this.cmbBottomLevel.SelectedIndex > this.cmbTopLevel.SelectedIndex)
			{
				MessageBox.Show("楼梯顶高低于楼梯底部.", "盈建科提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
				return;
			}
		}

		private void hyTbWellWidth_TextChanged(object sender, EventArgs e)
		{
		}

		private void hyTbTopOffset_Validating(object sender, CancelEventArgs e)
		{
			if ("" == this.hyTbTopOffset.Text)
			{
				return;
			}
			this.hyTbTopOffset.Text = YJKRevitStairs.StairsModel.CommonUnit.Common.StrToDouble(this.hyTbTopOffset.Text, 0.0).ToString("f2");
			if (this.m_TopLevel.Id == this.m_BottomLevel.Id && this.TopOffset <= this.BottomOffset)
			{
				MessageBox.Show("楼梯顶高低于楼梯底部.", "盈建科提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
				this.hyTbTopOffset.Focus();
				return;
			}
			double num = 0.0;
			if (!ValueValidatingKit.ValidatingDouble(this.hyTbTopOffset.Text, ValidatingType.None, ref num))
			{
				MessageBox.Show("楼梯顶高参数不正确.", "盈建科提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
				e.Cancel = true;
				return;
			}
			if (this.IsNotValidRunMinTread())
			{
				FormParamManager.MessageBoxWarning(FormParamManager.m_strRunMinTreadChkTip);
				this.hyTbTopOffset.Focus();
				return;
			}
		}

		private void hyTbBottomOffset_Validating(object sender, CancelEventArgs e)
		{
			if ("" == this.hyTbBottomOffset.Text)
			{
				return;
			}
			this.hyTbBottomOffset.Text = YJKRevitStairs.StairsModel.CommonUnit.Common.StrToDouble(this.hyTbBottomOffset.Text, 0.0).ToString("f2");
			if (this.m_TopLevel.Id == this.m_BottomLevel.Id && this.TopOffset <= this.BottomOffset)
			{
				MessageBox.Show("楼梯顶高低于楼梯底部.", "盈建科提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
				this.hyTbBottomOffset.Focus();
				return;
			}
			double num = 0.0;
			if (!ValueValidatingKit.ValidatingDouble(this.hyTbBottomOffset.Text, ValidatingType.None, ref num))
			{
				MessageBox.Show("起始高度参数不正确.", "盈建科提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
				e.Cancel = true;
				return;
			}
			if (this.IsNotValidRunMinTread())
			{
				FormParamManager.MessageBoxWarning(FormParamManager.m_strRunMinTreadChkTip);
				this.hyTbBottomOffset.Focus();
				return;
			}
		}

		private void hyTbRunWidth_Validating(object sender, CancelEventArgs e)
		{
			if ("" == this.hyTbRunWidth.Text)
			{
				return;
			}
			this.hyTbRunWidth.Text = Convert.ToDouble(this.hyTbRunWidth.Text).ToString("f2");
			this.WellWidth = this.StairsWidth - this.RunWidth * 2.0;
			if (1E-09 >= this.WellWidth)
			{
				this.WellWidth = 0.0;
			}
			double num = this.StairsWidth - this.RunWidth * 2.0 - this.WellWidth;
			double num2 = 0.0;
			if (!ValueValidatingKit.ValidatingDouble(this.hyTbRunWidth.Text, ValidatingType.GreaterThanZero, ref num2) || !ValueValidatingKit.ValidatingDouble(num.ToString(), ValidatingType.GreaterThanAndEqualZero, ref num2))
			{
				MessageBox.Show("梯段净宽参数不正确.", "盈建科提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
				this.RunWidth = this.m_listStairsData.ElementAt(0);
				e.Cancel = true;
				return;
			}
			this.UpdateStairsData();
			this.m_MainPreviewer.Refresh();
		}

		private void hyTbStairsWidth_Validating(object sender, CancelEventArgs e)
		{
			if ("" == this.hyTbStairsWidth.Text)
			{
				return;
			}
			this.hyTbStairsWidth.Text = Convert.ToDouble(this.hyTbStairsWidth.Text).ToString("f2");
			double num = 0.0;
			if (!ValueValidatingKit.ValidatingDouble(this.hyTbStairsWidth.Text, ValidatingType.GreaterThanZero, ref num))
			{
				MessageBox.Show("梯段净宽参数不正确.", "盈建科提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
				this.StairsWidth = this.m_listStairsData.ElementAt(1);
				e.Cancel = true;
				return;
			}
			this.WellWidth = this.StairsWidth - this.RunWidth * 2.0;
			if (1E-09 >= this.WellWidth)
			{
				this.RunWidth = this.StairsWidth / 2.0;
				this.WellWidth = 0.0;
			}
			this.UpdateStairsData();
			this.m_MainPreviewer.Refresh();
		}

		private void hyTbTreadHeight_Validating(object sender, CancelEventArgs e)
		{
			if ("" == this.hyTbTreadHeight.Text)
			{
				return;
			}
			this.hyTbTreadHeight.Text = Convert.ToDouble(this.hyTbTreadHeight.Text).ToString("f2");
			double num = 0.0;
			if (!ValueValidatingKit.ValidatingDouble(this.hyTbTreadHeight.Text, ValidatingType.GreaterThanZero, ref num))
			{
				MessageBox.Show("踏步高度参数不正确.", "盈建科提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
				e.Cancel = true;
				this.TreadHeight = this.m_listStairsData.ElementAt(2);
				return;
			}
			if (this.IsNotValidRunMinTread())
			{
				FormParamManager.MessageBoxWarning(FormParamManager.m_strRunMinTreadChkTip);
				e.Cancel = true;
				this.TreadHeight = this.m_listStairsData.ElementAt(2);
				return;
			}
			this.UpdateStairsData();
		}

		private void hyTbTreadDepth_Validating(object sender, CancelEventArgs e)
		{
			if ("" == this.hyTbTreadDepth.Text)
			{
				return;
			}
			this.hyTbTreadDepth.Text = Convert.ToDouble(this.hyTbTreadDepth.Text).ToString("f2");
			double num = 0.0;
			if (!ValueValidatingKit.ValidatingDouble(this.hyTbTreadDepth.Text, ValidatingType.GreaterThanZero, ref num))
			{
				MessageBox.Show("踏步宽度参数不正确.", "盈建科提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
				e.Cancel = true;
				this.TreadDepth = this.m_listStairsData.ElementAt(3);
				return;
			}
			this.UpdateStairsData();
		}

		private void hyTbBeamWidth_Validating(object sender, CancelEventArgs e)
		{
			if ("" == this.hyTbBeamWidth.Text)
			{
				return;
			}
			this.hyTbBeamWidth.Text = Convert.ToDouble(this.hyTbBeamWidth.Text).ToString("f2");
			double num = 0.0;
			if (!ValueValidatingKit.ValidatingDouble(this.hyTbBeamWidth.Text, ValidatingType.GreaterThanZero, ref num))
			{
				MessageBox.Show("梯梁宽度参数不正确.", "盈建科提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
				e.Cancel = true;
				this.BeamWidth = this.m_listStairsData.ElementAt(4);
				return;
			}
			this.UpdateStairsData();
		}

		private void hyTbBeamHeight_Validating(object sender, CancelEventArgs e)
		{
			if ("" == this.hyTbBeamHeight.Text)
			{
				return;
			}
			this.hyTbBeamHeight.Text = Convert.ToDouble(this.hyTbBeamHeight.Text).ToString("f2");
			double num = 0.0;
			if (!ValueValidatingKit.ValidatingDouble(this.hyTbBeamHeight.Text, ValidatingType.GreaterThanZero, ref num))
			{
				MessageBox.Show("梯梁高度参数不正确.", "盈建科提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
				e.Cancel = true;
				this.BeamHeight = this.m_listStairsData.ElementAt(5);
				return;
			}
			this.UpdateStairsData();
		}

		private void hyTbLandingWidth_Validating(object sender, CancelEventArgs e)
		{
			if ("" == this.hyTbLandingWidth.Text)
			{
				return;
			}
			this.hyTbLandingWidth.Text = Convert.ToDouble(this.hyTbLandingWidth.Text).ToString("f2");
			double num = 0.0;
			if (!ValueValidatingKit.ValidatingDouble(this.hyTbLandingWidth.Text, ValidatingType.GreaterThanZero, ref num))
			{
				MessageBox.Show("平台宽度参数不正确.", "盈建科提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
				e.Cancel = true;
				this.LandingWidth = this.m_listStairsData.ElementAt(6);
				return;
			}
			this.UpdateStairsData();
		}

		private void hyTbRotateAngle_Validating(object sender, CancelEventArgs e)
		{
			if ("" == this.hyTbRotateAngle.Text)
			{
				return;
			}
			this.hyTbRotateAngle.Text = YJKRevitStairs.StairsModel.CommonUnit.Common.StrToDouble(this.hyTbRotateAngle.Text, 0.0).ToString("f2");
			double num = 0.0;
			if (!ValueValidatingKit.ValidatingDouble(this.hyTbRotateAngle.Text, ValidatingType.Minus2PITo2PI, ref num))
			{
				MessageBox.Show("旋转角度参数不正确.", "盈建科提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
				e.Cancel = true;
				this.RotateAngle = this.m_listStairsData.ElementAt(7);
				return;
			}
			this.UpdateStairsData();
		}

		private void cmbTopLevel_Validating(object sender, CancelEventArgs e)
		{
			if (this.cmbBottomLevel.SelectedIndex > this.cmbTopLevel.SelectedIndex)
			{
				MessageBox.Show("楼梯顶部低于楼梯底部.", "盈建科提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
				e.Cancel = true;
				return;
			}
		}

		private void cmbBottomLevel_Validating(object sender, CancelEventArgs e)
		{
			if (this.cmbBottomLevel.SelectedIndex > this.cmbTopLevel.SelectedIndex)
			{
				MessageBox.Show("楼梯顶部低于楼梯底部.", "盈建科提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
				e.Cancel = true;
				return;
			}
		}

		private void hyTbWellWidth_Validating(object sender, CancelEventArgs e)
		{
			this.WellWidth = this.WellWidth;
		}

		private void btnRunWidth_Click(object sender, EventArgs e)
		{
			this.m_MeasureType = CrossingStairsForm.MeasureType.MT_RunWidth;
			this.hyTbRunWidth.Focus();
		}

		private void btnStairsWidth_Click(object sender, EventArgs e)
		{
			this.m_MeasureType = CrossingStairsForm.MeasureType.MT_StairsWidth;
			this.hyTbStairsWidth.Focus();
		}

		private void btnRotateAngle_Click(object sender, EventArgs e)
		{
			this.m_MeasureType = CrossingStairsForm.MeasureType.MT_Angle;
		}

		private void btnChangeInsertPoint_Click(object sender, EventArgs e)
		{
			int num = this.m_BasePointIndex + 1;
			this.m_BasePointIndex = num % 4;
			this.m_MainPreviewer.Refresh();
		}

		private void btnOk_Click(object sender, EventArgs e)
		{
			if (StairsFormManager.IsInvalidFormInput(this))
			{
				return;
			}
			this.m_MeasureType = CrossingStairsForm.MeasureType.MT_None;
			string message = "";
			if (!this.ValidatingDataParam(ref message))
			{
				DialogResult dialogResult = YJKMessageBox.Show(message, MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation);
				if (DialogResult.Cancel == dialogResult)
				{
					return;
				}
				if (DialogResult.OK == dialogResult)
				{
					base.DialogResult = DialogResult.OK;
					base.Close();
				}
			}
			base.DialogResult = DialogResult.OK;
		}

		private void nudTreadCount_ValueChanged(object sender, EventArgs e)
		{
			CrossingStairsForm.ValveChangeType valveChangeType = this.isAddNumericUpDown(this.nudTreadCount);
			if (valveChangeType == CrossingStairsForm.ValveChangeType.VCT_None)
			{
				return;
			}
			if (CrossingStairsForm.ValveChangeType.VCT_AddOne == valveChangeType)
			{
				this.ParametersCalculate(CrossingStairsForm.ParametersChangeType.PCT_TreadCountAdd);
			}
			else if (CrossingStairsForm.ValveChangeType.VCT_SubtractOne == valveChangeType)
			{
				this.ParametersCalculate(CrossingStairsForm.ParametersChangeType.PCT_TreadCountSub);
			}
			this.m_MainPreviewer.Refresh();
		}

		private void nudOneRunTreadCount_ValueChanged(object sender, EventArgs e)
		{
			CrossingStairsForm.ValveChangeType valveChangeType = this.isAddNumericUpDown(this.nudOneRunTreadCount);
			if (valveChangeType == CrossingStairsForm.ValveChangeType.VCT_None)
			{
				return;
			}
			if (CrossingStairsForm.ValveChangeType.VCT_AddOne == valveChangeType)
			{
				this.ParametersCalculate(CrossingStairsForm.ParametersChangeType.PCT_OneRunTreadCountAdd);
			}
			else if (CrossingStairsForm.ValveChangeType.VCT_SubtractOne == valveChangeType)
			{
				this.ParametersCalculate(CrossingStairsForm.ParametersChangeType.PCT_OneRunTreadCountSub);
			}
			this.m_MainPreviewer.Refresh();
		}

		private void nudTwoRunTreadCount_ValueChanged(object sender, EventArgs e)
		{
			CrossingStairsForm.ValveChangeType valveChangeType = this.isAddNumericUpDown(this.nudTwoRunTreadCount);
			if (valveChangeType == CrossingStairsForm.ValveChangeType.VCT_None)
			{
				return;
			}
			if (CrossingStairsForm.ValveChangeType.VCT_AddOne == valveChangeType)
			{
				this.ParametersCalculate(CrossingStairsForm.ParametersChangeType.PCT_TwoRunTreadCountAdd);
			}
			else if (CrossingStairsForm.ValveChangeType.VCT_SubtractOne == valveChangeType)
			{
				this.ParametersCalculate(CrossingStairsForm.ParametersChangeType.PCT_TwoRunTreadCountSub);
			}
			this.m_MainPreviewer.Refresh();
		}

		private void cmbTopLevel_SelectedIndexChanged(object sender, EventArgs e)
		{
			int selectedIndex = this.cmbTopLevel.SelectedIndex;
			int selectedIndex2 = this.cmbBottomLevel.SelectedIndex;
			this.m_TopLevel = this.m_listAllLevels.ElementAt(selectedIndex);
			this.hyTbTopOffset.Text = "0.00";
			if (-1 == selectedIndex2)
			{
				return;
			}
			if (selectedIndex == selectedIndex2)
			{
				if (this.m_listAllLevels.Count - 1 == selectedIndex)
				{
					this.m_dLevelValue = YJKRevitStairs.StairsModel.CommonUnit.Common.FeetToMM(this.m_TopLevel.Elevation - this.m_listAllLevels.ElementAt(selectedIndex - 1).Elevation);
				}
				else
				{
					this.m_dLevelValue = YJKRevitStairs.StairsModel.CommonUnit.Common.FeetToMM(this.m_listAllLevels.ElementAt(selectedIndex2 + 1).Elevation - this.m_BottomLevel.Elevation);
				}
				this.m_dStairsHeight = this.m_dLevelValue;
				this.TopOffset = this.m_dLevelValue;
				this.m_dLevelValue = 0.0;
			}
			else
			{
				this.m_dStairsHeight = 0.0;
				this.m_dLevelValue = YJKRevitStairs.StairsModel.CommonUnit.Common.FeetToMM(this.m_TopLevel.Elevation - this.m_BottomLevel.Elevation);
			}
			this.ParametersCalculate(CrossingStairsForm.ParametersChangeType.PCT_TreadHeight);
			this.m_MainPreviewer.Refresh();
		}

		private void cmbBottomLevel_SelectedIndexChanged(object sender, EventArgs e)
		{
			int selectedIndex = this.cmbTopLevel.SelectedIndex;
			int selectedIndex2 = this.cmbBottomLevel.SelectedIndex;
			this.m_BottomLevel = this.m_listAllLevels.ElementAt(selectedIndex2);
			this.hyTbBottomOffset.Text = "0.00";
			this.m_dBottomElevation = YJKRevitStairs.StairsModel.CommonUnit.Common.FeetToMM(this.m_BottomLevel.Elevation);
			if (selectedIndex == selectedIndex2)
			{
				if (this.m_listAllLevels.Count - 1 == selectedIndex)
				{
					this.m_dLevelValue = YJKRevitStairs.StairsModel.CommonUnit.Common.FeetToMM(this.m_TopLevel.Elevation - this.m_listAllLevels.ElementAt(selectedIndex - 1).Elevation);
				}
				else
				{
					this.m_dLevelValue = YJKRevitStairs.StairsModel.CommonUnit.Common.FeetToMM(this.m_listAllLevels.ElementAt(selectedIndex2 + 1).Elevation - this.m_BottomLevel.Elevation);
				}
				this.m_dStairsHeight = this.m_dLevelValue;
				this.TopOffset = this.m_dLevelValue;
				this.m_dLevelValue = 0.0;
			}
			else
			{
				this.m_dStairsHeight = 0.0;
				this.m_dLevelValue = YJKRevitStairs.StairsModel.CommonUnit.Common.FeetToMM(this.m_TopLevel.Elevation - this.m_BottomLevel.Elevation);
			}
			this.ParametersCalculate(CrossingStairsForm.ParametersChangeType.PCT_TreadHeight);
			this.m_MainPreviewer.Refresh();
		}

		public const double _epsDouble = 1E-09;

		private ExternalCommandData m_Revit;

		private Previewer m_MainPreviewer;

		private CrossingStairsKit m_StairsDrawingKit;

		private ComponentTypeManager m_ComponentTypeManager;

		private List<Level> m_listAllLevels;

		private CrossingStairsForm.MeasureType m_MeasureType;

		private XYZ m_BasePoint;

		private int m_BasePointIndex;

		private bool m_Calculating;

		private bool m_bLeftSideUp = true;

		private double m_dBottomElevation;

		private double m_dLevelValue;

		private Level m_TopLevel;

		private Level m_BottomLevel;

		private List<double> m_listStairsData;

		private double m_dStairsHeight;

		private const int m_nRiserSubTread = 2;

		private int m_nOneRunCmpTreadCnt = 3;

		private int m_nTwoRunCmpTreadCnt = 3;

		public enum MeasureType
		{
			MT_None,
			MT_RunWidth,
			MT_StairsWidth,
			MT_Angle
		}

		public enum ValveChangeType
		{
			VCT_None,
			VCT_AddOne,
			VCT_SubtractOne,
			VCT_ValveChanged
		}

		private enum ParametersChangeType
		{
			PCT_TreadHeight,
			PCT_TreadCount,
			PCT_TreadCountAdd,
			PCT_TreadCountSub,
			PCT_OneRunTreadCount,
			PCT_OneRunTreadCountAdd,
			PCT_OneRunTreadCountSub,
			PCT_TwoRunTreadCount,
			PCT_TwoRunTreadCountAdd,
			PCT_TwoRunTreadCountSub
		}
	}
}
